/**
 * 水印指令watermarker
 */
const watermarker = (str, el, font, textColor) => {
    // 水印文字，父元素，字体，文字颜色
    const canvas = document.createElement('canvas')
    el.appendChild(canvas);
    canvas.width = 200;
    canvas.height = 150;
    canvas.style.display = 'none';
    const ctx = can.getContext('2d');
    ctx.rotate((-20 * Math.PI) / 180);
    ctx.font = font || '16px Microsoft JhengHei';
    ctx.fillStyle = textColor || 'rgba(180, 180, 180, 0.3)';
    ctx.textAlign = 'left';
    ctx.textBaseline = 'Middle';
    ctx.fillText(str, canvas.width / 10, canvas.height / 2);
    ctx.style.backgroundImage = 'url(' + canvas.toDataURL('image/png') + ')';
}

export default {
    bind(el, binding) {
        watermarker(binding.value.text, el, binding.value.font, binding.value.textColor);
    }
}